/**
 * 2017年5月7日
 */
package cn.edu.bjtu.entity.impl.local.tiny;

import java.io.File;

import javax.servlet.http.HttpServletRequest;

import cn.edu.bjtu.entity.impl.local.SelfContainedTask;
import cn.edu.bjtu.entity.impl.local.tiny.lambda.Request2String;
import cn.edu.bjtu.settings.ApplicationConfiguration;
import util.io.DocumentIDVectorReader;
import util.io.SVMNodesWriter;

/**
 * @author Alex
 *
 */
public class Trans2StdLibSVMForamtTask extends SelfContainedTask<String>{

	/**
	 * @param req
	 */
	String dir = null;
	String filename;
	String targetDir = null;
	public Trans2StdLibSVMForamtTask(HttpServletRequest req,Request2String whichDir) {
		super(req);
		dir = whichDir.apply(req);
		this.filename = req.getParameter("filename");
		
	}

	@Override
	protected void fireInternal() throws Exception {
		DocumentIDVectorReader reader = new DocumentIDVectorReader(new File(dir,filename));
		reader.read();
		targetDir = ApplicationConfiguration.getInstance().getProperty("LIBSVM_DATA_DIR");
		new SVMNodesWriter(new File(targetDir,filename), reader.getVx(), reader.getVy());
		this.resultMap.put("tip", "转的成功.");
		this.msg = "转换成功,请刷新数据集管理以查看最新文件状态";
	}

	@Override
	public String javaClassResult() {
		return msg;
	}

}
